package com.example.administrator.kaohedemo.Store;

import com.example.administrator.kaohedemo.Action.Action;
import com.example.administrator.kaohedemo.Action.Actions;
import com.squareup.otto.Subscribe;

/**
 * Created by Administrator on 2016/6/21.
 */
public class TaskStore extends Store {

    private static TaskStore taskStore;
    private static TaskStoreChanged taskStoreChanged;

    public static TaskStore getInstense(){
        if (taskStore==null){
            taskStore=new TaskStore();
        }
        return taskStore;
    }

    @Override
    @Subscribe
    public void onAction(Action action) {

        GetTaskStoreChanged();

        String type=action.getType();
        switch (type){
            case Actions.TaskActions.TYPE_ITEM_ONCLICK:
                taskStoreChanged.setType(type);
                taskStoreChanged.setPosition((int)action.getMap().get(Actions.TaskActions.KEY_ITEM_SELECT));
                UIChanged();
                break;
            case Actions.TaskActions.TYPE_ITEM_ONLONGCLICK:
                break;
        }
    }

    private void GetTaskStoreChanged(){
        if (taskStoreChanged==null){
            taskStoreChanged=new TaskStoreChanged();
        }
    }

    @Override
    protected StoreChanged changed() {
        return taskStoreChanged;
    }

    public class TaskStoreChanged implements StoreChanged{
        public String type;
        public int position;

        public void setType(String type){
            this.type=type;
        }

        public String getType(){
            return type;
        }

        public void setPosition(int position) {
            this.position = position;
        }

        public int getPosition() {
            return position;
        }
    }
}
